using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.SessionState;

/// <summary>
/// Summary description for OrderFoodDetails
/// </summary>
public class OrderFoodDetailsBll
{
    public OrderFoodDetailsBll()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    #region List all oreder food Details
    public SqlDataReader ListAllOrderFoodDetails()
    {
        return (SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_List", null));
    }
    #endregion

    #region Create order food Details
    public int CreateOrderFoodDetails(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
               // new SqlParameter("@orderDetailsID", SqlDbType.BigInt, 8),
                new SqlParameter("@orderID", SqlDbType.VarChar, 5),
                new SqlParameter("@foodID", SqlDbType.VarChar, 10),
                new SqlParameter("@quantity", SqlDbType.Int),
                new SqlParameter("@resID", SqlDbType.VarChar,10)
            };
       // cmdParms[0].Value = orderFoodDetailsInfo.OrderDetailsID;
        cmdParms[0].Value = orderFoodDetailsInfo.OrderID;
        cmdParms[1].Value = orderFoodDetailsInfo.FoodID;
        cmdParms[2].Value = orderFoodDetailsInfo.Quantity;
        cmdParms[3].Value = orderFoodDetailsInfo.ResID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_Create", cmdParms);

        return result;
    }
    #endregion

    #region Update order food Details
    public int UpdateOrderFoodDetails(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderDetailsID", SqlDbType.BigInt, 8),
                new SqlParameter("@orderID", SqlDbType.VarChar, 5),
                new SqlParameter("@foodID", SqlDbType.VarChar, 10),
                new SqlParameter("@quantity", SqlDbType.Int),
                new SqlParameter("@resID", SqlDbType.VarChar,10)
            };
        cmdParms[0].Value = orderFoodDetailsInfo.OrderDetailsID;
        cmdParms[1].Value = orderFoodDetailsInfo.OrderID;
        cmdParms[2].Value = orderFoodDetailsInfo.FoodID;
        cmdParms[3].Value = orderFoodDetailsInfo.Quantity;
        cmdParms[4].Value = orderFoodDetailsInfo.ResID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_Update", cmdParms);

        return result;
    }
    #endregion

    #region Delete order food Details
    public int DeleteOrderFoodDetails(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5)
            };
        cmdParms[0].Value = orderFoodDetailsInfo.OrderID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_Delete", cmdParms);
        return result;
    }
    #endregion

    #region Delete food seleted in order food details
    public int DeleteFood(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5),
                new SqlParameter("@foodID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = orderFoodDetailsInfo.OrderID;
        cmdParms[1].Value = orderFoodDetailsInfo.FoodID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_DeleteFood", cmdParms);
        return result;
    }
    #endregion

    #region Price Food
    public int PriceFood(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5)
            };
        cmdParms[0].Value = orderFoodDetailsInfo.OrderID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_PriceFood", cmdParms);
        return result;
    }
    #endregion

    #region Total price order
    public int TotalOrder(OrderingFoodDetailsInfo orderFoodDetailsInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5)
            };
        cmdParms[0].Value = orderFoodDetailsInfo.OrderID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFoodDetails_TotalPriceOrder", cmdParms);
        return result;
    }
    #endregion

    #region Cancel Order food details
    public SqlDataReader CancelOrderFoodDetails(OrderingFoodDetailsInfo info)
    {
        SqlParameter[] cmdParms = {
            new SqlParameter("@orderID", SqlDbType.VarChar , 5)
        };
        cmdParms[0].Value = info.OrderID;
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                              "sp_OrderingFoodDetails_CancelOrderFood", cmdParms);
    }
    #endregion
}

